<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                template="./template/template_padrao.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="conteudo">
        <p:panel header="Manutenção de Sprint">
            <p:messages id="msgInicial"/>
            <h:form id="formSprint">
                <p:commandButton value="Adicionar" icon="ui-icon-plus" onclick="dlgSprint.show()" update=":dlgCad"
                                 action="#{sprintMB.reset()}"/>
                <p:separator style="margin:10px 0;"/>
                <p:dataTable var="sprint" value="#{sprintMB.sprints}" emptyMessage="Nenhum Registro Encontrado"
                             paginator="true" rows="5" paginatorPosition="bottom">
                    <p:column headerText="Nome" sortBy="#{sprint.nome}">
                        <h:outputText value="#{sprint.nome}"/>
                    </p:column>
                    <p:column headerText="Produto" sortBy="#{sprint.produto.nome}">
                        <h:outputText value="#{sprint.produto.nome}"/>
                    </p:column>
                    <p:column headerText="Objetivo" sortBy="#{sprint.objetivo}">
                        <h:outputText value="#{sprint.objetivo}"/>
                    </p:column>
                    <p:column id="dataInicioColumn" sortBy="#{sprint.dataInicio}"   
                              headerText="Data Início">  
                        <h:outputText value="#{sprint.dataInicio}">
                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm" />
                        </h:outputText>  
                    </p:column>
                    <p:column id="dataFimColumn" sortBy="#{sprint.dataFim}"   
                              headerText="Data Fim">  
                        <h:outputText value="#{sprint.dataFim}">
                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm" />
                        </h:outputText>  
                    </p:column>
                    <p:column headerText="Descrição" sortBy="#{sprint.descricao}">
                        <h:outputText value="#{sprint.descricao}"/>
                    </p:column>

                    <p:column headerText="Ações">
                        <p:commandButton icon="ui-icon-pencil" title="Editar" onclick="dlgSprint.show()" update=":dlgCad">
                            <f:setPropertyActionListener target="#{sprintMB.sprint}" value="#{sprint}"/>
                        </p:commandButton>
                        <p:commandButton icon="ui-icon-trash" title="Excluir" onclick="confirmation.show()">
                            <f:setPropertyActionListener target="#{sprintMB.sprint}" value="#{sprint}"/>
                        </p:commandButton>
                        <p:commandButton icon="ui-icon-plus" value="Adicionar Itens Backlog" onclick="widget_backlogPicker.show()" update=":sprintBacklog"
                                         action="#{sprintMB.selecionarBacklogs()}">
                            <f:setPropertyActionListener target="#{sprintMB.sprint}" value="#{sprint}"/>
                        </p:commandButton>
                    </p:column>
                </p:dataTable> 
            </h:form>
        </p:panel>

        <p:dialog header="Cadastrar Sprint" widgetVar="dlgSprint" modal="true">
            <p:outputPanel>
                <h:form id="dlgCad">
                    <p:messages id="msgCad"/>
                    <h:panelGrid>
                        <h:outputText value="Nome: *"/>
                        <p:inputText value="#{sprintMB.sprint.nome}" size="60" required="true"
                                     requiredMessage="Nome é um campo Obrigatório"/>
                        <h:outputText value="Produto: *"/>
                        <h:selectOneMenu required="true" requiredMessage="Selecione um Produto" value="#{sprintMB.produto}" converter="entityConverter">                            
                            <f:selectItems value="#{sprintMB.produtos}" 
                                           var="produto"
                                           itemLabel="#{produto.nome}"
                                           itemValue="#{produto}"/>
                        </h:selectOneMenu>

                        <h:outputText value="Objetivo: *" style="font-weight: bold"/>
                        <p:inputText value="#{sprintMB.sprint.objetivo}" size="80" required="true"
                                     requiredMessage="Objetivo é um campo Obrigatório"/>
                        <h:outputText value="Data Início: *" /> 
                        <p:calendar value="#{sprintMB.sprint.dataInicio}" required="true" pattern="dd/MM/yyyy HH:mm" effect="fold" navigator="true" display="inline">
                            <p:ajax event="dateSelect" listener="#{spintMB.handleDataInicioSelect}" update=":dlgCad:msgCad" />
                        </p:calendar>
                        <h:outputText value="Data Fim: *" /> 
                        <p:calendar value="#{sprintMB.sprint.dataFim}" required="true" pattern="dd/MM/yyyy HH:mm" effect="fold" navigator="true" display="inline">
                            <p:ajax event="dateSelect" listener="#{sprintMB.handleDataFimSelect}" update=":dlgCad:msgCad" />
                        </p:calendar>
                        <h:outputText value="Descrição:" style="font-weight: bold;margin-right: 20px;"/>
                        <p:inputTextarea value="#{sprintMB.sprint.descricao}" cols="40" />
                        <p:separator style="margin:10px 0;"/>
                        <h:panelGrid columns="2" style="float: right">
                            <p:commandButton value="Salvar" action="#{sprintMB.salvar()}" update=":msgInicial :formSprint :dlgCad:msgCad" />
                            <p:commandButton value="Fechar" onclick="dlgCad.hide()" immediate="true"/>
                        </h:panelGrid>
                    </h:panelGrid>
                </h:form>
            </p:outputPanel>
        </p:dialog>


        <h:form prependId="false">
            <p:confirmDialog id="confirmDialog" message="Tem certeza que deseja excluir esse dado?"  
                             header="Exclusão" severity="alert" widgetVar="confirmation">  

                <p:commandButton id="confirm" value="Sim" oncomplete="confirmation.hide()"  
                                 actionListener="#{sprintMB.remover()}" update=":formSprint" />  
                <p:commandButton id="decline" value="Não" onclick="confirmation.hide()" type="button" />   

            </p:confirmDialog>  
        </h:form>


        <p:dialog header="Selecionar Backlogs para #{sprintMB.sprint.nome}" widgetVar="widget_backlogPicker" id="backlogPicker" modal="true" width="480">
            <h:form id="sprintBacklog">
                <p:messages />
                <p:pickList id="listaBacklog" value="#{sprintMB.backlogs}"  
                            var="backlog"
                            itemValue="#{backlog}"
                            itemLabel="#{backlog.descricao}"
                            converter="entityConverter">  
                    <f:facet name="sourceCaption">Backlogs</f:facet>  
                    <f:facet name="targetCaption">Selecionados</f:facet>  
                </p:pickList>
                <p:spacer/>
                <center>
                    <p:commandButton value="Salvar"  action="#{sprintMB.salvarBacklogs()}" update="sprintBacklog" 
                                     icon="ui-icon-check" oncomplete="widget_backlogPicker.hide();"/>
                </center>
            </h:form>
        </p:dialog>


    </ui:define>
</ui:composition>